package com.yixin.hospital.controller;

import cn.hutool.extra.servlet.ServletUtil;
import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.domain.UserIpWhiteList;
import com.yixin.hospital.entity.dto.req.userIpWhiteList.UserIpWhiteListAddReqDTO;
import com.yixin.hospital.entity.dto.req.userIpWhiteList.UserIpWhiteListEditReqDTO;
import com.yixin.hospital.service.UserIpWhiteListService;
import com.yixin.hospital.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/user-ip-white-list")
@Api(value = "用户ip白名单管理", tags = "用户ip白名单管理")
@Slf4j
public class UserIpWhiteListController {

    @Resource
    private UserIpWhiteListService userIpWhiteListService;


    @GetMapping("/list")
    @ApiOperation(value = "用户ip白名单列表")
    public ApiResult list() {
        List<UserIpWhiteList> list = userIpWhiteListService.list();
        return ApiResult.success(list);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加用户ip白名单")
    public ApiResult add(@Valid @RequestBody UserIpWhiteListAddReqDTO userIpWhiteListAddReqDTO, HttpServletRequest request) {
        return userIpWhiteListService.add(userIpWhiteListAddReqDTO, request);
    }

    @PutMapping("/edit")
    @ApiOperation(value = "更新用户ip白名单")
    public ApiResult edit(@Valid @RequestBody UserIpWhiteListEditReqDTO userIpWhiteListEditReqDTO, HttpServletRequest request) {
        return userIpWhiteListService.edit(userIpWhiteListEditReqDTO, request);
    }

    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "删除用户ip白名单")
    public ApiResult remove(@PathVariable int id) {
        userIpWhiteListService.removeById(id);
        return ApiResult.success();
    }
}
